package com.lanou.zhihu.service.impl;

import com.lanou.zhihu.entity.FollowQuestion;
import com.lanou.zhihu.entity.User;
import com.lanou.zhihu.mapper.FollowQuestionMapper;
import com.lanou.zhihu.service.FollowQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by QuChao on 2018/10/30.
 */
@Service
public class FollowQuestionServiceImpl implements FollowQuestionService {
    @Autowired
    private FollowQuestionMapper followQuestionMapper;

    @Override
    public boolean followQuestion(User user, Integer qid) {
        Map<String, Object> map = new HashMap<>();
        map.put("uid", user.getId());
        map.put("qid", qid);
        Integer result = followQuestionMapper.insert(map);
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean getFollowInfo(Integer uid, Integer qid) {
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("qid", qid);
        FollowQuestion followQuestion = followQuestionMapper.getFollowInfo(map);
        if (followQuestion != null) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean cancelQuestion(User user, Integer qid) {
        Map<String, Object> map = new HashMap<>();
        map.put("uid", user.getId());
        map.put("qid", qid);
        Integer result = followQuestionMapper.cancelQuestion(map);
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }
}
